<?php
/**
 * Copyright (C) 2013  Artur Tolstenco
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/* use it if you want to map the sql datatype to php datatype... 
 * set in the Db_Table protected $_rowClass = 'Agenziaentrate_Model_ModelRowAbstract'
 */
class Agenziaentrate_Model_ModelRowAbstract extends Zend_Db_Table_Row {
	protected $_dataTypes = array(
			'bit' => 'int',
			'tinyint' => 'int',
			'bool' => 'bool',
			'boolean' => 'bool',
			'smallint' => 'int',
			'mediumint' => 'int',
			'int' => 'int',
			'integer' => 'int',
			'bigint' => 'float',
			'serial' => 'int',
			'float' => 'float',
			'real' => 'float',
			'numeric' => 'float',
			'money' => 'float',
			'double' => 'float',
			'double precision' => 'float',
			'decimal' => 'float',
			'dec' => 'float',
			'fixed' => 'float',
			'year' => 'int'
	);

	/**
	 * Initialize object
	 *
	 * Called from {@link __construct()} as final step of object instantiation.
	 *
	 * @return void
	*/
	public function init() {
		$table = $this->getTable();
		if ($table) {
			$cols = $table->info(Zend_Db_Table_Abstract::METADATA);
			foreach ($cols as $name => $col) {
				$dataType = strtolower($col['DATA_TYPE']);
				if (array_key_exists($dataType, $this->_dataTypes)) {
					settype($this->_data[$name], $this->_dataTypes[$dataType]);
				}
			}
		}
	}
}
